package Version2_1;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class BootStrap {

    private int port=8080;

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public void startUp() throws IOException {

        //创建一个服务器Socket对象
        ServerSocket serverSocket = new ServerSocket(port);
        System.out.println("=====>>>Minicat start on port：" + port);

        while (true){

            //接收一个请求后
            Socket socket = serverSocket.accept();
            System.out.println("接收一个请求后");

            Request request = new Request(socket.getInputStream());
            Response response = new Response(socket.getOutputStream());

            response.outputHtml(request.getUrl());
            socket.close();
        }

    }

    public static void main(String[] args) {
        BootStrap bootStrap = new BootStrap();

        try {
            bootStrap.startUp();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
